﻿using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using QuanLyThongTinCoSo.Common;
using QuanLyThongTinCoSo.Entity;
using QuanLyThongTinCoSo.Forms.Settings;

namespace QuanLyThongTinCoSo
{
    public partial class MDI : Form
    {
        #region Global properties

        public User CurrentUser { get; set; }

        public string UserStatus
        {
            get { return textUserStatus.Text; }
            set { textUserStatus.Text = value; }
        }

        public MenuStrip TopMenu
        {
            get { return menuStrip1; }
        }

        public ToolStripStatusLabel Status
        {
            get { return toolStripStatusLabel; }
        }
        

        #endregion

        public MDI()
        {
            InitializeComponent();
            Image image = Image.FromFile("..\\..\\Images\\Firefighter-edit.jpg");
            
            mainPicture.Image = image;
            
        }

        private void Exit(object sender, EventArgs e)
        {
            Close();
        }

        private void ChangeSize(object sender, EventArgs e)
        {
            var controls = Controls.Find("mainPanel", true);
            if (controls.Length > 0)
            {
                controls[0].Size = new Size(Size.Width - 16, Size.Height);
            }
        }
        
        private void ShowLogin()
        {
            if (Utilities.OpenForm(this, typeof(LoginForm).Name))
            {
                var form = new LoginForm { MdiParent = this, Dock = DockStyle.Fill };
                mainPanel.Visible = false;

                form.Show();
            }
        }

        private void FormLoad(object sender, EventArgs e)
        {
            if (CurrentUser == null)
            {
                ShowMenu(false);
                ShowLogin();
            }
        }

        private void Logout(object sender, EventArgs e)
        {
            CurrentUser = null;
            UserStatus = string.Empty;

            ShowMenu(false);
            ShowLogin();
        }

        public void ShowMenu(bool flag)
        {
            menuStrip1.Visible = flag;
        }

        private void OpenGuideline(object sender, EventArgs e)
        {
            var filePath = Path.Combine(Application.StartupPath, "Huong dan su dung.pdf");
            Process.Start(filePath);
        }

        private void ViewUsers(object sender, EventArgs e)
        {
            if (Utilities.OpenForm(this, typeof(ViewUser).Name))
            {
                mainPanel.Visible = false;

                var form = new ViewUser { MdiParent = this, Dock = DockStyle.Fill };
                form.Show();
            }
        }
    }
}
